﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OntologyFormDesigner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Initialize();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void statusPanel_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
        private void tabPage2_Click(object sender, EventArgs e)
        {


        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Object widgetForm = new Widget.WidgetForm();
            XMLModelReader.Instance.read("C:\\Users\\v\\Desktop\\saveFileDialog1.xml", ref widgetForm);

            form.Size = new Size(((Widget.WidgetForm)widgetForm).WidgetSize.Width, ((Widget.WidgetForm)widgetForm).WidgetSize.Height);
            loadXml(((Widget.WidgetForm)widgetForm).Ontology.Path, ((Widget.WidgetForm)widgetForm).Ontology.Name);
            form.Update();
            foreach (OntologyUtility.Interfaces.IWidget control in ((Widget.WidgetForm)widgetForm).Widgets)
            {
                try
                {
                    ((OntologyFormDesigner.DesignerHost.DesignerHost)host).AddByLoad((IComponent)control);
                    if (typeof(OntologyUtility.Interfaces.IWidgetWithItems).IsAssignableFrom(control.GetType()))
                        ((OntologyUtility.Interfaces.IWidgetWithItems)control).update();
                    form.Controls.Add((Control)control);
                    form.Update();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Add Widget by load, si è verificato un errore: \n {0}", ex.ToString());
                }
                //form.Controls.Add((Control)control);
                //Console.WriteLine("X: " + control.WidgetLocation.X);
                //Console.WriteLine("Y: " + control.WidgetLocation.Y);
                //form.Update();
            }


            foreach (OntologyUtility.Interfaces.IWidgetViewer control in ((Widget.WidgetForm)widgetForm).ViewerWidgets)
            {
                /*form.Controls.Add((Control)control);
                form.Update();*/
                ((OntologyFormDesigner.DesignerHost.DesignerHost)host).Add((IComponent)control);
                form.Controls.Add((Control)control);
                form.Update();
            }

            form.Size = new Size(((Widget.WidgetForm)widgetForm).WidgetSize.Width, ((Widget.WidgetForm)widgetForm).WidgetSize.Height);
        }
    }
}
